<template>
  <view class="huakuai">
    <view class="coll-l-comenter" v-for="(item,index) in baseLister" :key="index">
      <uni-collapse ref="collapseView">
        <uni-collapse-item>
          <template v-slot:title>
            <view class="coll-l-comenter-top">
              <view>
                <view style="font-weight:bold;font-size: 30rpx" class="coll-l-comenter-top-center">
                  <text :selectable="true">单号:{{ "" }}{{ item.recipientApplyId }}</text>
                </view>
                <view class="coll-l-comenter-top-center" style="font-size: 27rpx;color: #AFAEAC">
                  <label>申领时间：{{ item.createTime }}</label>
                </view>
                <view class="coll-l-comenter-top-center" style="font-size: 27rpx;color: #AFAEAC">
                  <label>计划领用时间：{{ item.plantime }}</label>
                </view>
                <view class="coll-l-comenter-top-center" v-if="type==='2'" style="font-size: 27rpx;color: #AFAEAC">
                  <label>站址编码：{{ item.siteId }}</label>
                </view>
              </view>
              <view class="coll-l-comenter-top-right" :style="getColor(item.isAllOs)">
                {{ item.osName }}
              </view>
            </view>
          </template>
          <view class="mingxi" v-for="(num,index2) in item.applyDetails" :key="index2">
            <view v-if="type==='3'" style="font-size: 27rpx;color: #AFAEAC">
              <text>站址编码：{{ num.siteId }}</text>
            </view>
            <view style="font-size: 27rpx;color: #AFAEAC">
              <text>物料编码：{{ num.categoryCode }}</text>
            </view>
            <text v-if="num.categoryName" :selectable="true"
                  style="display: inline-block;font-size: 27rpx;color: #AFAEAC">
              {{ num.categoryName != null ? "物料名称：" + num.categoryName : "" }}
            </text>
            <view style="display: flex;font-size: 27rpx;color: #AFAEAC">
              <view style="flex: 1">申领数量：{{ num.amount }}</view>
              <view style="flex: 1">撤销领用数量：{{ num.backAmount }}</view>
            </view>
            <view style="font-size: 27rpx;color: #AFAEAC">
              <label>累计出库数量：
                <text>{{ num.osAmount }}</text>
              </label>
            </view>
            <view style="width: 100%;padding: 20rpx 6% 10rpx 0;display: flex;"
                  v-if="(item.isPush ==='0' && item.applyTypeId !=='6') && prjInfo.isEdit === '1'">
              <button style="width:180rpx ;height:50rpx;font-size: 26rpx;line-height: 50rpx;"
                      type="warn" size="mini"
                      @click="()=>syncWarehousing(item.recipientApplyId,'01')">
                同步仓储
              </button>
            </view>
            <view style="width: 100%;padding: 20rpx 6% 10rpx 0;display: flex;"
                v-else-if="(item.isPush === '2' || (item.isPush === '0' && item.applyTypeId === '6'))&& prjInfo.isEdit === '1'">
              <button style="width:180rpx ;height:50rpx;font-size: 26rpx;line-height: 50rpx;"
                      type="warn" size="mini"
                      @click="()=>syncWarehousing(item.recipientApplyId,'02')">
                  同步仓储
              </button>
            </view>
            <view style="width: 100%;padding: 20rpx 6% 10rpx 0;display: flex;"
                  v-else-if="num.backingAmount >0 && prjInfo.isEdit === '1'">
              <button style="width:180rpx ;height:50rpx;font-size: 26rpx;line-height: 50rpx;"
                      type="warn" size="mini"
                      @click="()=>syncWarehousingReset(num.applySno)">
                同步仓储
              </button>
            </view>
            <view style="width: 100%;padding: 20rpx 6% 10rpx 0;display: flex;" v-else>
              <button style="width:180rpx ;height:50rpx;font-size: 26rpx;line-height: 50rpx;"
                      type="warn" size="mini"
                      @click="deleteclick(index,index2,num.applySno,num)"
                      v-if="num.noReceiveAmount !=='0' && prjInfo.isEdit === '1' && +num.applyType !==6">撤销领用
              </button>
              <button style="width:230rpx ;height:50rpx;font-size: 26rpx;line-height: 50rpx;"
                      type="warn" size="mini"
                      @click="jumpOrderText(num.applySno,num.categoryCode,num.dwjl,num.subPrjId)"
                      v-if="num.osAmount>0">查看出库明细
              </button>
            </view>
          </view>
        </uni-collapse-item>
      </uni-collapse>
    </view>
    <!-- 提示 -->
    <view
        style="width: 100%;padding: 10rpx 0;text-align: center;background-color:#00000008; color:#737373 ;margin: 15rpx 0;">
      ---没有更多了---
    </view>
  </view>
</template>
<script>

export default {
  name: "applicationFormList",
  components: {},
  props: {
    type: {
      type: String,
      default: ''
    },
    baseLister: {
      type: Array,
      default: () => []
    },
    prjId:{
      type: String,
      default: ''
    },
    prjInfo: {
      type: Object,
      default: () => ({})
    },
  },
  data() {
    return {}
  },
  methods: {
    // 获取 出库 入库 字体的颜色
    getColor(code) {
      //'0', '未出库', '1', '部分出库', '2', '已完成'
      if (code === '2') {
        return 'color: #00CC66;'
      } else if (code === '0') {
        return 'color: #C53F3F;'
      } else {
        return 'color: #FF9933;'
      }
    },
    //同步仓储接口调用
    requestSyncWarehousing(url) {
      let that = this;
      this.$axios.post(url).then((res) => {
        uni.showModal({
          title: '温馨提示',
          content: res.message,
          confirmColor: '#eb4b4b',
          showCancel: false,
          success: function () {
            that.$emit('changeList')
          }
        })
      })
    },
    // 同步仓储 同步申领
    syncWarehousing(applyId,type) {
        let that = this;
        if(type === '01'){
            this.requestSyncWarehousing('/material/api/receive/equip/doRetryApply?applyId=' + applyId)
        }else{
            const params = {
                retreatDetailId:'',
                recipientApplyId:applyId,
            }
            this.$axios.post('/material/api/material/transfer/sendMaterialTransferInfo',params).then((res) => {
                uni.showModal({
                    title: '温馨提示',
                    content: res.message,
                    confirmColor: '#eb4b4b',
                    showCancel: false,
                    success: function () {
                        that.$emit('changeList')
                    }
                })
            })
        }
    },
    //同步撤销申领
    syncWarehousingReset(applySno) {
      this.requestSyncWarehousing('/material/api/receive/equip/doAppRetryBackInfo?applySno=' + applySno)
    },
    // 撤销领用
    deleteclick(e, a, c, item) {
      console.log('item', item)
      uni.navigateTo({
        url: './deletelingyong?index=' + e + '&prjId=' + this.prjId + '&index2=' + a + '&type=' + this.type + '&applyId=' + c + "&item=" +
            encodeURIComponent(JSON.stringify(item)),
      });
    },
    // 查看出库明细
    jumpOrderText(applyId, categoryCode, dwjl, subPrjId) {
      uni.navigateTo({
        url: './outboundOrderText?applyId=' + applyId + '&subPrjId=' + subPrjId + '&type=' + this.type + '&categoryCode=' + categoryCode +
            '&dwjl=' + dwjl
      });
    },
  }
}
</script>

<style scoped lang="scss">
@import "@/common/common-ui.css";

.huakuai {
  padding-top: 80rpx;
  width: 100%;
  height: 100%;
  .coll-l-comenter {
    width: 98%;
    margin: auto;
    margin-top: 6rpx;
    border-radius: 20rpx;
    overflow: hidden;

    .coll-l-comenter-top {
      width: 100%;
      padding: 10rpx 3%;
      //display: flex;
      //justify-content: space-between;
      position: relative;

      .coll-l-comenter-top-center {
        width: 100%;
        display: flex;
        white-space: nowrap;
      }

      .coll-l-comenter-top-right {
        display: flex;
        align-items: center;
        width: 140rpx;
        justify-content: center;
        position: absolute;
        height: 100%;
        right: 0;
        top: 0;
        font-size: 32rpx;
      }
    }

    .mingxi {
      width: 100%;
      padding: 10rpx 6% 10rpx 70rpx;
      margin-bottom: 4rpx;
      background-color: #00000010;
      text-align: left;
      color: #737373;
    }
  }

}
</style>